package club.justwill.single.persistence.store;

import club.justwill.single.persistence.document.ProjectSupport;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Component;

/**
 * Created by xiangnan on 16-1-14.
 */
@Component
@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
public class ProjectSupportStore extends MongoDbStore<ProjectSupport> {
    public ProjectSupport searchProjectSupport(Long projectId) {
        return mongoTemplate.findOne(Query.query(Criteria.where("project_id").is(projectId)), ProjectSupport.class);
    }

    public void removeByBatchNo(String batchNo) {
        mongoTemplate.remove(Query.query(Criteria.where("batch_no").is(batchNo)),ProjectSupport.class);
    }

    public ProjectSupport getByBatchNo(String batchNo){
        return mongoTemplate.findOne(Query.query(Criteria.where("batch_no").is(batchNo)),ProjectSupport.class);
    }
}
